// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Code generated by sidekick. DO NOT EDIT.

pub mod fleet_routing {
    use crate::Result;

    /// A builder for [FleetRouting][crate::client::FleetRouting].
    ///
    /// ```
    /// # tokio_test::block_on(async {
    /// # use google_cloud_optimization_v1::*;
    /// # use builder::fleet_routing::ClientBuilder;
    /// # use client::FleetRouting;
    /// let builder : ClientBuilder = FleetRouting::builder();
    /// let client = builder
    ///     .with_endpoint("https://cloudoptimization.googleapis.com")
    ///     .build().await?;
    /// # gax::client_builder::Result::<()>::Ok(()) });
    /// ```
    pub type ClientBuilder =
        gax::client_builder::ClientBuilder<client::Factory, gaxi::options::Credentials>;

    pub(crate) mod client {
        use super::super::super::client::FleetRouting;
        pub struct Factory;
        impl gax::client_builder::internal::ClientFactory for Factory {
            type Client = FleetRouting;
            type Credentials = gaxi::options::Credentials;
            async fn build(
                self,
                config: gaxi::options::ClientConfig,
            ) -> gax::client_builder::Result<Self::Client> {
                Self::Client::new(config).await
            }
        }
    }

    /// Common implementation for [crate::client::FleetRouting] request builders.
    #[derive(Clone, Debug)]
    pub(crate) struct RequestBuilder<R: std::default::Default> {
        stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
        request: R,
        options: gax::options::RequestOptions,
    }

    impl<R> RequestBuilder<R>
    where
        R: std::default::Default,
    {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
        ) -> Self {
            Self {
                stub,
                request: R::default(),
                options: gax::options::RequestOptions::default(),
            }
        }
    }

    /// The request builder for [FleetRouting::optimize_tours][crate::client::FleetRouting::optimize_tours] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_optimization_v1::builder;
    /// use builder::fleet_routing::OptimizeTours;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> OptimizeTours {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct OptimizeTours(RequestBuilder<crate::model::OptimizeToursRequest>);

    impl OptimizeTours {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::OptimizeToursRequest>>(mut self, v: V) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<crate::model::OptimizeToursResponse> {
            (*self.0.stub)
                .optimize_tours(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [parent][crate::model::OptimizeToursRequest::parent].
        ///
        /// This is a **required** field for requests.
        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.parent = v.into();
            self
        }

        /// Sets the value of [timeout][crate::model::OptimizeToursRequest::timeout].
        pub fn set_timeout<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<wkt::Duration>,
        {
            self.0.request.timeout = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [timeout][crate::model::OptimizeToursRequest::timeout].
        pub fn set_or_clear_timeout<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<wkt::Duration>,
        {
            self.0.request.timeout = v.map(|x| x.into());
            self
        }

        /// Sets the value of [model][crate::model::OptimizeToursRequest::model].
        pub fn set_model<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::ShipmentModel>,
        {
            self.0.request.model = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [model][crate::model::OptimizeToursRequest::model].
        pub fn set_or_clear_model<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<crate::model::ShipmentModel>,
        {
            self.0.request.model = v.map(|x| x.into());
            self
        }

        /// Sets the value of [solving_mode][crate::model::OptimizeToursRequest::solving_mode].
        pub fn set_solving_mode<T: Into<crate::model::optimize_tours_request::SolvingMode>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.solving_mode = v.into();
            self
        }

        /// Sets the value of [search_mode][crate::model::OptimizeToursRequest::search_mode].
        pub fn set_search_mode<T: Into<crate::model::optimize_tours_request::SearchMode>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.search_mode = v.into();
            self
        }

        /// Sets the value of [injected_first_solution_routes][crate::model::OptimizeToursRequest::injected_first_solution_routes].
        pub fn set_injected_first_solution_routes<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::ShipmentRoute>,
        {
            use std::iter::Iterator;
            self.0.request.injected_first_solution_routes =
                v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [injected_solution_constraint][crate::model::OptimizeToursRequest::injected_solution_constraint].
        pub fn set_injected_solution_constraint<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
        {
            self.0.request.injected_solution_constraint = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [injected_solution_constraint][crate::model::OptimizeToursRequest::injected_solution_constraint].
        pub fn set_or_clear_injected_solution_constraint<T>(
            mut self,
            v: std::option::Option<T>,
        ) -> Self
        where
            T: std::convert::Into<crate::model::InjectedSolutionConstraint>,
        {
            self.0.request.injected_solution_constraint = v.map(|x| x.into());
            self
        }

        /// Sets the value of [refresh_details_routes][crate::model::OptimizeToursRequest::refresh_details_routes].
        pub fn set_refresh_details_routes<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::ShipmentRoute>,
        {
            use std::iter::Iterator;
            self.0.request.refresh_details_routes = v.into_iter().map(|i| i.into()).collect();
            self
        }

        /// Sets the value of [interpret_injected_solutions_using_labels][crate::model::OptimizeToursRequest::interpret_injected_solutions_using_labels].
        pub fn set_interpret_injected_solutions_using_labels<T: Into<bool>>(
            mut self,
            v: T,
        ) -> Self {
            self.0.request.interpret_injected_solutions_using_labels = v.into();
            self
        }

        /// Sets the value of [consider_road_traffic][crate::model::OptimizeToursRequest::consider_road_traffic].
        pub fn set_consider_road_traffic<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.consider_road_traffic = v.into();
            self
        }

        /// Sets the value of [populate_polylines][crate::model::OptimizeToursRequest::populate_polylines].
        pub fn set_populate_polylines<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.populate_polylines = v.into();
            self
        }

        /// Sets the value of [populate_transition_polylines][crate::model::OptimizeToursRequest::populate_transition_polylines].
        pub fn set_populate_transition_polylines<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.populate_transition_polylines = v.into();
            self
        }

        /// Sets the value of [allow_large_deadline_despite_interruption_risk][crate::model::OptimizeToursRequest::allow_large_deadline_despite_interruption_risk].
        pub fn set_allow_large_deadline_despite_interruption_risk<T: Into<bool>>(
            mut self,
            v: T,
        ) -> Self {
            self.0
                .request
                .allow_large_deadline_despite_interruption_risk = v.into();
            self
        }

        /// Sets the value of [use_geodesic_distances][crate::model::OptimizeToursRequest::use_geodesic_distances].
        pub fn set_use_geodesic_distances<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.use_geodesic_distances = v.into();
            self
        }

        /// Sets the value of [geodesic_meters_per_second][crate::model::OptimizeToursRequest::geodesic_meters_per_second].
        pub fn set_geodesic_meters_per_second<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<f64>,
        {
            self.0.request.geodesic_meters_per_second = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [geodesic_meters_per_second][crate::model::OptimizeToursRequest::geodesic_meters_per_second].
        pub fn set_or_clear_geodesic_meters_per_second<T>(
            mut self,
            v: std::option::Option<T>,
        ) -> Self
        where
            T: std::convert::Into<f64>,
        {
            self.0.request.geodesic_meters_per_second = v.map(|x| x.into());
            self
        }

        /// Sets the value of [max_validation_errors][crate::model::OptimizeToursRequest::max_validation_errors].
        pub fn set_max_validation_errors<T>(mut self, v: T) -> Self
        where
            T: std::convert::Into<i32>,
        {
            self.0.request.max_validation_errors = std::option::Option::Some(v.into());
            self
        }

        /// Sets or clears the value of [max_validation_errors][crate::model::OptimizeToursRequest::max_validation_errors].
        pub fn set_or_clear_max_validation_errors<T>(mut self, v: std::option::Option<T>) -> Self
        where
            T: std::convert::Into<i32>,
        {
            self.0.request.max_validation_errors = v.map(|x| x.into());
            self
        }

        /// Sets the value of [label][crate::model::OptimizeToursRequest::label].
        pub fn set_label<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.label = v.into();
            self
        }

        /// Sets the value of [populate_travel_step_polylines][crate::model::OptimizeToursRequest::populate_travel_step_polylines].
        #[deprecated]
        pub fn set_populate_travel_step_polylines<T: Into<bool>>(mut self, v: T) -> Self {
            self.0.request.populate_travel_step_polylines = v.into();
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for OptimizeTours {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [FleetRouting::batch_optimize_tours][crate::client::FleetRouting::batch_optimize_tours] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_optimization_v1::builder;
    /// use builder::fleet_routing::BatchOptimizeTours;
    /// # tokio_test::block_on(async {
    /// use lro::Poller;
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.poller().until_done().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> BatchOptimizeTours {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct BatchOptimizeTours(RequestBuilder<crate::model::BatchOptimizeToursRequest>);

    impl BatchOptimizeTours {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<crate::model::BatchOptimizeToursRequest>>(
            mut self,
            v: V,
        ) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        ///
        /// # Long running operations
        ///
        /// This starts, but does not poll, a longrunning operation. More information
        /// on [batch_optimize_tours][crate::client::FleetRouting::batch_optimize_tours].
        pub async fn send(self) -> Result<longrunning::model::Operation> {
            (*self.0.stub)
                .batch_optimize_tours(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Creates a [Poller][lro::Poller] to work with `batch_optimize_tours`.
        pub fn poller(
            self,
        ) -> impl lro::Poller<crate::model::BatchOptimizeToursResponse, crate::model::AsyncModelMetadata>
        {
            type Operation = lro::internal::Operation<
                crate::model::BatchOptimizeToursResponse,
                crate::model::AsyncModelMetadata,
            >;
            let polling_error_policy = self.0.stub.get_polling_error_policy(&self.0.options);
            let polling_backoff_policy = self.0.stub.get_polling_backoff_policy(&self.0.options);

            let stub = self.0.stub.clone();
            let mut options = self.0.options.clone();
            options.set_retry_policy(gax::retry_policy::NeverRetry);
            let query = move |name| {
                let stub = stub.clone();
                let options = options.clone();
                async {
                    let op = GetOperation::new(stub)
                        .set_name(name)
                        .with_options(options)
                        .send()
                        .await?;
                    Ok(Operation::new(op))
                }
            };

            let start = move || async {
                let op = self.send().await?;
                Ok(Operation::new(op))
            };

            lro::internal::new_poller(polling_error_policy, polling_backoff_policy, start, query)
        }

        /// Sets the value of [parent][crate::model::BatchOptimizeToursRequest::parent].
        ///
        /// This is a **required** field for requests.
        pub fn set_parent<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.parent = v.into();
            self
        }

        /// Sets the value of [model_configs][crate::model::BatchOptimizeToursRequest::model_configs].
        ///
        /// This is a **required** field for requests.
        pub fn set_model_configs<T, V>(mut self, v: T) -> Self
        where
            T: std::iter::IntoIterator<Item = V>,
            V: std::convert::Into<crate::model::batch_optimize_tours_request::AsyncModelConfig>,
        {
            use std::iter::Iterator;
            self.0.request.model_configs = v.into_iter().map(|i| i.into()).collect();
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for BatchOptimizeTours {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }

    /// The request builder for [FleetRouting::get_operation][crate::client::FleetRouting::get_operation] calls.
    ///
    /// # Example
    /// ```no_run
    /// # use google_cloud_optimization_v1::builder;
    /// use builder::fleet_routing::GetOperation;
    /// # tokio_test::block_on(async {
    ///
    /// let builder = prepare_request_builder();
    /// let response = builder.send().await?;
    /// # gax::Result::<()>::Ok(()) });
    ///
    /// fn prepare_request_builder() -> GetOperation {
    ///   # panic!();
    ///   // ... details omitted ...
    /// }
    /// ```
    #[derive(Clone, Debug)]
    pub struct GetOperation(RequestBuilder<longrunning::model::GetOperationRequest>);

    impl GetOperation {
        pub(crate) fn new(
            stub: std::sync::Arc<dyn super::super::stub::dynamic::FleetRouting>,
        ) -> Self {
            Self(RequestBuilder::new(stub))
        }

        /// Sets the full request, replacing any prior values.
        pub fn with_request<V: Into<longrunning::model::GetOperationRequest>>(
            mut self,
            v: V,
        ) -> Self {
            self.0.request = v.into();
            self
        }

        /// Sets all the options, replacing any prior values.
        pub fn with_options<V: Into<gax::options::RequestOptions>>(mut self, v: V) -> Self {
            self.0.options = v.into();
            self
        }

        /// Sends the request.
        pub async fn send(self) -> Result<longrunning::model::Operation> {
            (*self.0.stub)
                .get_operation(self.0.request, self.0.options)
                .await
                .map(gax::response::Response::into_body)
        }

        /// Sets the value of [name][longrunning::model::GetOperationRequest::name].
        pub fn set_name<T: Into<std::string::String>>(mut self, v: T) -> Self {
            self.0.request.name = v.into();
            self
        }
    }

    #[doc(hidden)]
    impl gax::options::internal::RequestBuilder for GetOperation {
        fn request_options(&mut self) -> &mut gax::options::RequestOptions {
            &mut self.0.options
        }
    }
}
